extends CharacterBody2D

var gravity:float = ProjectSettings.get("physics/2d/default_gravity")
var speed =200.0 
var jump = -300.0

func _physics_process(delta: float) -> void:
	
	if not is_on_floor():
		velocity.y += gravity * delta
	
	var dir = Input.get_axis("left","right")
	velocity.x = dir * speed
	
	if is_on_floor() and Input.is_action_just_pressed("jump"):
		velocity.y = jump
		
		
	if is_on_floor():
		if is_zero_approx(dir):
			$AnimationPlayer.play("idle")
		else :
			$AnimationPlayer.play("runing")
	else:
		$AnimationPlayer.play("jump")
		
		
	if not is_zero_approx(dir):
		$Body.flip_h = dir<0
	move_and_slide()
